package main

import (
	"fmt"
	"os"

	"linclaus.com/pkg/hmac"
)

type SignAceGatewayProxyAuthData struct {
	Version     string
	ProxyMode   hmac.ProxyMode
	ProxyValue  string
	ProxyScheme string
	ProxyHost   string
	IsUnderlay  bool
	AccessKey   string
	SecretKey   string
	Expiration  int64
	Method      string
	TLSConf     string
	Path        string
	Body        string
}

func main() {
	// go run cmd/cube_gateway/main.go prometheus 100.65.0.215:31080
	// go run cmd/cube_gateway/main.go prometheus "[fdbd:dc41:fe:f800:2602:cbdf:698a:7041]:31080"
	// go run cmd/cube_gateway/main.go cube-agent 10.24.0.3:8031
	// go run cmd/cube_gateway/main.go apiserver /clusters/boe-tjjnsx-a8e6209f/healthz
	// go run cmd/cube_gateway/main.go apiserver /svc/boe-hbhldw-ctcucm-01-monitoring-apiserver/0610bd674798255175bcc2537b7d391d/api/v1/nodes
	// go run cmd/cube_gateway/main.go cube-agent "[fdbd:dc41:fe:f800:2602:b670:8d3e:6]:8031"
	args := os.Args
	if len(args) < 2 {
		fmt.Println("Usage: ./cube_gateway serivce proxy, Example: ./cube_gateway prometheus Node_IP:31080")
		return
	}
	service := args[1]
	proxyValue := args[2]
	switch service {
	case "prometheus":
		data := SignAceGatewayProxyAuthData{
			ProxyMode:   hmac.ProxyModeDirect,
			ProxyValue:  proxyValue,
			ProxyScheme: "http",
			ProxyHost:   "",
			IsUnderlay:  false,
			AccessKey:   "prometheus-ak",
			SecretKey:   "prometheus-sk",
			Expiration:  int64(3600 * 24 * 365 * 10),
		}
		auth, _ := hmac.SignAceGatewayProxyAuthV3(data.ProxyMode, data.ProxyValue, data.ProxyScheme, data.ProxyHost, data.IsUnderlay, data.AccessKey, data.SecretKey, data.Expiration)
		fmt.Println(auth)
	case "cube-agent":
		data := SignAceGatewayProxyAuthData{
			ProxyMode:   hmac.ProxyModeDirect,
			ProxyValue:  proxyValue,
			ProxyScheme: "https",
			ProxyHost:   "cube-agent.com:8031",
			IsUnderlay:  true,
			AccessKey:   "cube_resource_ak",
			SecretKey:   "cube_resource_sk",
			Expiration:  int64(3600 * 24 * 365 * 10),
			Method:      "POST",
			TLSConf:     "cube-agent",
			Path:        "/api/v1/nodes/tasks/exec",
			Body:        "{\n    \"timeout_seconds\": 1,\n    \"cmd\": \"pwd\",\n    \"callback_host\": \"https://bytesec.bytedance.com\",\n    \"callback_access_key\": \"0ec6635a87dfe646e89ae9b3b8ab39a6\",\n    \"callback_secret_key\": \"a162ca78e4e8ebc4481f807848026637\"\n}",
		}
		auth, _ := hmac.SignAceGatewayProxyAuthV4(data.ProxyMode, data.ProxyValue, data.ProxyScheme, data.ProxyHost, data.Method, data.IsUnderlay, data.AccessKey, data.SecretKey, data.Expiration, data.TLSConf, data.Path, data.Body)
		fmt.Println(auth)
	case "apiserver":
		data := SignAceGatewayProxyAuthData{
			ProxyMode:   hmac.ProxyModeRoute,
			ProxyValue:  "",
			ProxyScheme: "",
			ProxyHost:   "",
			IsUnderlay:  false,
			AccessKey:   "svc-boe-hbhldw-ctcucm-01-monitoring-apiserver-60df6a0c7fed31148257e2d9a4a94b7b",
			SecretKey:   "svc-boe-hbhldw-ctcucm-01-monitoring-apiserver-55f018192bd8c03db0a8f6f73cecee5e",
			Expiration:  int64(3600 * 24 * 365 * 10),
		}
		auth, _ := hmac.SignAceGatewayProxyAuthV2(data.ProxyMode, data.ProxyValue, data.ProxyScheme, data.ProxyHost, "GET", proxyValue, data.IsUnderlay, data.AccessKey, data.SecretKey, data.Expiration)
		fmt.Println(auth)
	}
}
